//
//  ZLPhotoCollectionViewCell.m
//  TripTogether
//
//  Created by dllo on 15/12/25.
//  Copyright © 2015年 杨泓晔. All rights reserved.
//

#import "ZLPhotoCollectionViewCell.h"
#import "SizeForLabel.h"

@interface ZLPhotoCollectionViewCell ()

@property (nonatomic, strong)UIView *myView;
@property (nonatomic, strong)UILabel *diDianLabel;
@property (nonatomic, strong)UILabel *timeLabel;
@property (nonatomic, strong)UILabel *textsLabel;

@property (nonatomic, strong)UIView *headView;
@property (nonatomic, strong)UIButton *backBtn;
@property (nonatomic, strong)UIButton *btn;

@end

@implementation ZLPhotoCollectionViewCell

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        self.photo_1600 = [[UIImageView alloc]init];
        [self.contentView addSubview:self.photo_1600];
        
        
        self.name = [[UILabel alloc]initWithFrame:CGRectMake(10, SCREEN_HEIGHT - 10*AUTO_HEIGHT, SCREEN_WIDTH - 10, 30*AUTO_HEIGHT)];
        [self.contentView addSubview:self.name];
        self.name.font = [UIFont systemFontOfSize:13.0f];
        
        self.myView = [[UIView alloc]init];
        self.myView.backgroundColor = [UIColor colorWithRed:0.98 green:0.96 blue:0.91 alpha:1];
        self.myView.alpha = 0.9;
        [self.contentView addSubview:self.myView];
        
        self.textsLabel = [[UILabel alloc]init];
        [self.myView addSubview:self.textsLabel];

        self.diDianLabel = [[UILabel alloc]init];
        [self.myView addSubview:self.diDianLabel];
        
        self.timeLabel = [[UILabel alloc]init];
        [self.myView addSubview:self.timeLabel];
        
        self.headView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 64*AUTO_HEIGHT)];
        self.headView.backgroundColor = [UIColor colorWithRed:0.98 green:0.96 blue:0.91 alpha:1];
        [self.contentView addSubview:self.headView];
        
        self.backBtn = [UIButton buttonWithType:(UIButtonTypeCustom)];
        self.backBtn.frame = CGRectMake(0, 20, 64*AUTO_WIDTH, 44*AUTO_HEIGHT);
        
        
        [self.backBtn setImage:[UIImage imageNamed:@"icon_nav_back_button@2x.png"] forState:(UIControlStateNormal)];
        [self.headView addSubview:self.backBtn];
        self.backBtn.tag = 1001;
        [self.backBtn addTarget:self action:@selector(backBtnAction:) forControlEvents:(UIControlEventTouchUpInside)];
        
        
        self.btn = [UIButton buttonWithType:(UIButtonTypeCustom)];
        self.btn.frame = CGRectMake(300*AUTO_WIDTH, 20, 75 * AUTO_WIDTH, 44*AUTO_HEIGHT);
        [self.btn setTitle:@"查看游记" forState:(UIControlStateNormal)];
        self.btn.tag = 1002;
//        self.btn.layer.borderWidth = 2;
        self.btn.layer.cornerRadius = 5*AUTO_HEIGHT;
        self.btn.layer.borderColor = [[UIColor lightGrayColor] CGColor];
        
        [self.headView addSubview:self.btn];
        [self.btn addTarget:self action:@selector(backBtnAction:) forControlEvents:UIControlEventTouchUpInside];
    }
    return self;
}

-(void)setZlTapM:(ZLTapModel *)zlTapM
{
    //取出照片的宽高
    NSInteger h = zlTapM.zlphone_infoM.h;
    NSInteger w = zlTapM.zlphone_infoM.w;
    CGFloat height = SCREEN_WIDTH * h/w;
    
    if (height > SCREEN_HEIGHT) {
        height = SCREEN_HEIGHT;
    }
    
    self.photo_1600.frame = CGRectMake(0, 0, SCREEN_WIDTH, height);
    self.photo_1600.center = self.contentView.center;
    
    [self.photo_1600 sd_setImageWithURL:[NSURL URLWithString:zlTapM.photo_1600] placeholderImage:PICHOLDEER];
    self.photo_1600.userInteractionEnabled = YES;
    
    if (zlTapM.model.length == 0) {
        self.name.text = [zlTapM.zlPoiM.name stringByAppendingString:@"  "];
    }else{
        NSString *str = [zlTapM.zlPoiM.name stringByAppendingString:@"  "];
        self.name.text = [str stringByAppendingString:zlTapM.model];
    }
    
    CGSize digestHeight = [SizeForLabel labelRectWithSize:CGSizeMake(SCREEN_WIDTH, 120) LabelText:zlTapM.text Font:[UIFont systemFontOfSize:14.0f]];
    zlTapM.height = digestHeight.height;
    
    self.myView.frame = CGRectMake(0,SCREEN_HEIGHT -zlTapM.height - 20*AUTO_HEIGHT, SCREEN_WIDTH, zlTapM.height + 50*AUTO_HEIGHT);
    self.textsLabel.lineBreakMode = NSLineBreakByWordWrapping;
    self.textsLabel.numberOfLines = 0;
    
    self.textsLabel.frame = CGRectMake(10,0, 355 * AUTO_WIDTH, zlTapM.height);
    
    self.timeLabel.frame = CGRectMake(10,zlTapM.height*AUTO_HEIGHT, 355 * AUTO_WIDTH, 30*AUTO_HEIGHT);
    
    self.textsLabel.text = zlTapM.text;
    self.textsLabel.font = [UIFont systemFontOfSize:16.0f];
    NSString *string = [zlTapM.zlPoiM.name stringByAppendingString:@"  "];
    self.timeLabel.text = [string stringByAppendingString:zlTapM.local_time];
    self.timeLabel.font = [UIFont systemFontOfSize:14.0f];
    
    
    
    
    
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapAction:)];
    [self.photo_1600 addGestureRecognizer:tap];
}

- (void)tapAction:(UITapGestureRecognizer *)tap
{
    
    [self.photoCollectionViewCellDeletage tapPhoto:self.myView view:self.headView];
}

- (void)backBtnAction:(UIButton *)btn
{
    if (btn.tag == 1001) {
        [self.photoCollectionVCellDeletage back];
    }else{
        [self.photoCollectionVCellDeletage toYouJi];
    }
}


@end
